//
//  BaseTableViewController.swift
//  新浪微博
//
//  Created by 李赛 on 15/5/10.
//  Copyright (c) 2015年 李赛. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate{

    // 判断用户登录状态
    var userLogon = sharedUserAccount != nil
    // 访客登录视图
    var visitorLoginView : VisitorLoginView?
    
    override func loadView(){
        // 如果用户已经登录   直接返回
        if userLogon {
            super.loadView()
            return
        }
        
        // 替换根视图
        visitorLoginView = NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: nil, options: nil).last
            as? VisitorLoginView
        
        // 设置代理属性
        visitorLoginView?.delegate = self
        view = visitorLoginView
        // 添加导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Done, target: self, action: "didSelectedRegisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Done, target: self, action: "didSelectedLoginButton")
    }

    
    /// 注册按钮点击事件
    func didSelectedRegisterButton() {
        println("用户注册")
    }
    
    /// 登录按钮点击事件
    func didSelectedLoginButton() {
        println("用户登录")
        
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        // 以modal方式弹出窗口
        presentViewController(sb.instantiateInitialViewController() as! UIViewController, animated: true, completion: nil)
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return 0
    }


}
